/*
 * Created on 29/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view.stress_view;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.text.Position;

import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.StressController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdMenu;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnViewState;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.stress_view.command.DMatrixCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.stress_view.command.GetStressCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.stress_view.command.Help3Command;

/**
 * @author Francisca
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class StressView extends LearnView {  
	
	//  No da arvore: Stress
	private Command cMatrixCmd = new DMatrixCommand(parent);
	private Command getStressCmd = new GetStressCommand(parent);
	private Command help3Cmd = new Help3Command(parent);
	
	//	No Stress
    private CmdMenu itemCMatrix = new CmdMenu("C Matrix", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress2.gif")));
    private CmdMenu itemGetStress = new CmdMenu("Get Stress", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress2.gif")));
    private CmdMenu itemHelp3 = new CmdMenu("Help", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));

    
    //No Stress
    private CmdButton cMatrix = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress2.gif")));
    private CmdButton getStress = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress2.gif")));
    private CmdButton help3 = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
   
    private JMenu menuStressXStrain = new JMenu("StressXStrain");
    protected JToolBar stressXStrainToolBar = new JToolBar();
    
	public StressView(LearnInterface parent, FemModel m){
	    super(parent,m);
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new StressController(this));
		
		//Setting menu Stress
		menuStressXStrain.add(itemCMatrix);
		itemCMatrix.setCommand(cMatrixCmd);
		itemCMatrix.setEnabled(false);
		itemCMatrix.setMnemonic(KeyEvent.VK_C);
		itemCMatrix.addActionListener(parent);
        
		menuStressXStrain.add(itemGetStress);
		itemGetStress.setCommand(getStressCmd);
		itemGetStress.setEnabled(false);
		itemGetStress.setMnemonic(KeyEvent.VK_S);
		itemGetStress.addActionListener(parent);
		     
		menuStressXStrain.add(itemHelp3);
        itemHelp3.setCommand(help3Cmd);
        itemHelp3.setEnabled(false);
        itemHelp3.setMnemonic(KeyEvent.VK_H);
        itemHelp3.addActionListener(parent);
        
        stressXStrainToolBar.add(cMatrix);
        cMatrix.setToolTipText("C Matrix");
        cMatrix.addActionListener(parent);
        cMatrix.setCommand(cMatrixCmd);
        
        stressXStrainToolBar.add(getStress);
        getStress.setToolTipText("Get Stress");
        getStress.addActionListener(parent);
        getStress.setCommand(getStressCmd);
               
        stressXStrainToolBar.add(help3);
		help3.setToolTipText("Help");
		help3.addActionListener(parent);
		help3.setCommand(help3Cmd);
        
	}
	
	public void init(){
	    super.init();
			parent.getMenuPanel().removeAll();
			parent.getMenuPanel().add(menuFile);
			itemSave.setEnabled(true);
			itemSaveAs.setEnabled(true);
			itemClose.setEnabled(true);
			itemPrint.setEnabled(true);
			menuExport.setEnabled(true);
			menuImport.setEnabled(true);
			parent.getMenuPanel().add(menuEdit);
			parent.getMenuPanel().add(menuView);
			parent.getMenuPanel().add(menuStressXStrain);
			menuStressXStrain.setEnabled(true);
			itemCMatrix.setEnabled(true);
			itemGetStress.setEnabled(true);
			itemHelp3.setEnabled(true);
			parent.getMenuPanel().add(menuSettings);
			parent.getMenuPanel().add(menuHelp);
	        
			parent.getToolPanel().removeAll();
			parent.getToolPanel().add(fileToolBar);
			save.setEnabled(true);
			saveAs.setEnabled(true);
			print.setEnabled(true);
			delete.setEnabled(false);
			parent.getToolPanel().add(editToolBar);
			parent.getToolPanel().add(zoomToolBar);
			parent.getToolPanel().add(stressXStrainToolBar);
			cMatrix.setEnabled(true);
			getStress.setEnabled(true);
			help3.setEnabled(true);
							
	        parent.getConsolePanel().setVisible(true);
			
			grid.setEnabled(true);
			snap.setEnabled(true);
			
			this.getDrawingArea().setRepainting(false);
			this.getDrawingArea().repaint();
	        
			parent.getConsoleHandler().setToCommandMode();
			parent.getConsoleHandler().setKeybCommand(null);
			
			this.setStateButtons();
			
			parent.getTree().setEnabled(true);
			parent.getTree().setSelectionPath(parent.getTree().getNextMatch("StressXStrain", 0, Position.Bias.Forward));
			
			this.getController().compose();

			parent.getDrawPanel().removeAll();
			parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
			this.getDrawingArea().removeAllCommands();
			this.getDrawingArea().setClickedCommand(new SelectCommand(parent));
			this.getDrawingArea().setCursor();
			parent.getDrawPanel().repaint();
			parent.getDrawPanel().updateUI();
			
			parent.getJMenuBar().updateUI();
			parent.repaint();
	    }   

	public  JFrame getInterface(){
    	return parent;
    }
    
	public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }

}
